package com.dkt.android.base

import androidx.annotation.CallSuper
import com.dkt.android.mvp.presenter.RegisterPresenter
import com.dkt.android.utils.equalToFun
import com.dtb.utils.base.DtbBasePresenter
import com.dtb.utils.base.RxHandler


/**
 * @author: dtb
 * @email: wendaoyuqin1@gmail.com
 * @createTime: 19-3-14下午2:32
 */
abstract class BasePresenterImpl : DtbBasePresenter, RegisterPresenter {

    var registerSet: Any? = null
    open lateinit var handler: RxHandler

    open fun <T> T.equalToFunc(block: (T) -> Unit) {
        this.equalToFun(registerSet) { block(this) }
    }


    override fun register(view: Any?, handler: RxHandler) {
        this.registerSet = view
        this.handler = handler
        onCreate()
    }

    override fun onCreate() {
    }

    @CallSuper
    override fun onDestroy() {
        registerSet = null
        handler.removeCallbacksAndMessages(null)
    }
}